IF OBJECT_ID('dbo.RptAgrDemographicValidataionErrorDetail') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.RptAgrDemographicValidataionErrorDetail
    IF OBJECT_ID('dbo.RptAgrDemographicValidataionErrorDetail') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.RptAgrDemographicValidataionErrorDetail >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.RptAgrDemographicValidataionErrorDetail >>>'
END
go
-- =======================================================================
-- Procedure Name: dbo.RptAgrDemographicValidataionErrorDetail
--
-- Author:      Chris Bernard, Parallax Consulting LLC
--
-- Create date: 8/09/2007
--
-- Description: Source of Report, "RptAgrDemographicValidataionErrorDetail"
--                  In Insight DB Reporting Services
--
-- Parameters:  
-- 
--              
-- Returns:     INT, 0=Success, -1=Error
--
-- SampleCall:
-- EXECUTE dbo.RptAgrDemographicValidataionErrorDetail()
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 8/09/07     CB        Created
-- 4/28/2008   CB		 Added ability to view all errors for a insitiouion
-- =======================================================================
CREATE PROCEDURE dbo.RptAgrDemographicValidataionErrorDetail(@LogDate DATETIME,@ErrorCode VARCHAR(200),@Instiution VARCHAR(10),@Status VARCHAR(1))
AS
BEGIN
    -- Initial Settings
	SET NOCOUNT ON
     
    -- Declare Local Variables
    DECLARE   @Error INT,
              @RowCount INT,
              @BusinessUnit INT

    SET @BusinessUnit =0

	IF @Instiution= 'MGH'
    BEGIN
	  SET @BusinessUnit =1200
    END

    IF @Instiution= 'BWH'
    BEGIN
	  SET @BusinessUnit =2200
    END
    
    SELECT D.ErrorCode,
           BusinessUnit,
           PSFundNumber,FolderNumber,
		   PSValue,InfoEdValue,Status,
		   PSPrincipalInvestigator,PSProposalTitle,PSChiefCode,
		   PSSponsorName,PSProjectStart,PSProjectEnd,
		   PSBudgetStart,PSBudgetEnd,
		   Type
      FROM dbo.Stg_AgrDemographicValidataionErrorDetail D
           INNER JOIN Stg_AdmDemographicValidationError E ON D.ErrorCode = E.ErrorCode  
     WHERE LogDate =@LogDate AND (D.ErrorCode =@ErrorCode OR @ErrorCode = '0') AND
           BusinessUnit =@BusinessUnit AND Status =@Status
  ORDER BY BusinessUnit,PSFundNumber

    SELECT @Error=@@ERROR,@RowCount=@@ROWCOUNT
    IF @Error!=0
         RETURN -1
         
    -- Return Success
    RETURN 0
     
END
go

IF OBJECT_ID('dbo.RptAgrDemographicValidataionErrorDetail') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.RptAgrDemographicValidataionErrorDetail >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.RptAgrDemographicValidataionErrorDetail >>>'
go

GRANT EXECUTE ON dbo.RptAgrDemographicValidataionErrorDetail TO InsightReport,Insight
go


